package com.sitanyun.merchant.guide.model.impl;

import com.google.gson.Gson;
import com.sitanyun.merchant.guide.bean.DeleteBean;
import com.sitanyun.merchant.guide.bean.VersionBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.model.inter.IMainAModel;
import com.sitanyun.merchant.guide.presenter.callback.CallBack;
import com.sitanyun.merchant.guide.url.Urls;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;

import okhttp3.Call;
import okhttp3.MediaType;

public class MainAModelImpl implements IMainAModel {
    @Override
    public <T> void setversion(String platform, String appType, CallBack callBack) {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("platform", platform);
        hashMap.put("appType", appType);
        OkHttpUtils.postString()
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .addHeader("Content-Type", "application/json")
                .url(Urls.getVersion).content(new Gson().toJson(hashMap))
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                VersionBean baseEntity=  new Gson().fromJson(response, VersionBean.class);
            callBack.onSuccess(baseEntity);
            }
        });

    }

    @Override
    public <T> void setsave(String staffId, String deviceId, String regId, String deviceType, CallBack callBack) {
        HashMap<String, String> hashMap = new HashMap<String, String>();
            hashMap.put("staffId", staffId);
            hashMap.put("deviceId", deviceId);
            hashMap.put("regId", regId);
            hashMap.put("deviceType", deviceType);
            OkHttpUtils.postString()
                    .mediaType(MediaType.parse("application/json; charset=utf-8"))
                    .addHeader("Content-Type", "application/json")
                    .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                    .url(Urls.save).content(new Gson().toJson(hashMap))
                    .build().execute(new StringCallbacks() {
                @Override
                public void onError(Call call, Exception e, int id) {

                }

                @Override
                public void onResponse(String response, int id) {
                    DeleteBean baseEntity=  new Gson().fromJson(response, DeleteBean.class);
                    callBack.onSuccess(baseEntity);
                }
            });


    }
}
